home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d7
/
litecom6.arc
/
LCLIB.EXE
/
LITECOMM.H
< prev
next >
Wrap
Text File
|
1991-07-24
|
10KB
|
306 lines
/*
** litecomm.h
** Communications support for Datalight (tm) C
** Copyright (c) 1987 - 1991 - Information Technology, Ltd.,
** All Rights Reserved
** Revisions -
** 01 01/08/88 Modify for DLC 3.21
** remove lc_sbrk define
** 2.70 02/25/88 abandon DLC support
** 5.00 02/10/89 change CCB definition for new txready
** add define for lc_vport
** 6.00 04/24/91 change CCB definition to add support
** for status buffer, change variable sizes
** far pointers for single ISR
*/
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#define ERR (-1)
#include <stddef.h>
#ifndef LITECOMM_H /* if not already included */
#define LITECOMM_H 1
#define COM1BASE 0x3f8 /* base for com port 1 */
#define COM2BASE 0x2f8 /* base for com port 2 */
#define IRQ1 0x10 /* int req mask for port 1 - irq4 */
#define IRQ2 0x08 /* int req mask for port 2 - irq3 */
#define COM1VEC 0x0c /* vector for port 1 */
#define COM2VEC 0x0b /* vector for port 2 */
extern unsigned COM3BASE;
extern unsigned COM4BASE;
extern char IRQ3;
extern char IRQ4;
extern unsigned COM3VEC;
extern unsigned COM4VEC;
/*
** special control characters
*/
#define XON 0x11
#define XOFF 0x13
/*
** 8250 register defines (offsets from base)
*/
#define THREG 0 /* transmit hold register */
#define RDREG 0 /* input data register */
#define LSBDIV 0 /* least sig. byte of baud rate divisor */
#define MSBDIV 1 /* most sig, only when line ctl bit 7 = 1 */
#define IEREG 1 /* interrupt enable register */
#define IIDREG 2 /* interrupt ID register */
#define LCREG 3 /* line control register */
#define MCREG 4 /* modem control register */
#define LSREG 5 /* line status register */
#define MSREG 6 /* modem status register */
/*
** PARITY SETTINGS used in conjunction with above
*/
#define NPARITY 0x00 /* no parity */
#define OPARITY 0x08 /* odd parity */
#define EPARITY 0x18 /* even parity */
#define MPARITY 0x28 /* mark parity */
#define SPARITY 0x38 /* space parity */
/*
** DATA and STOP BIT settings
*/
#define BIT5 0x00 /* 5 data bits */
#define BIT6 0x01 /* 6 data bits */
#define BIT7 0x02 /* 7 data bits */
#define BIT8 0x03 /* 8 data bits */
#define STOP1 0x00 /* 1 stop bit */
#define STOP2 0x04 /* 2 stop bit */
/*
** setting for hardware flow control
*/
#define USEDSR 0x01
#define USECTS 0x02
#define USEDTR 0x04
#define USERTS 0x08
/*
** SPECIAL PURPOSE SETTINGS - internal use only
*/
#define BREAK_ON 0x40 /* enable transmitter break */
#define SETBAUD 0x80 /* enable access to baud rate divisor */
#define DTR 0x01 /* turn on DTR modem signal */
#define RTS 0x02 /* turn on RTS modem signal */
#define OUT2 0x08 /* enable OUT2 for interrupts */
#define LOOPBACK 0x10 /* enable loopback mode */
#define RDINT 0x01 /* enable receive data int */
#define THREINT 0x02 /* enable transmit hold reg empty int */
#define BRKINT 0x04 /* enable break/error int */
#define MSTINT 0x08 /* enable modem change int */
#define NOPEND 0x01 /* no interrupts pending */
#define INTMST 0x00 /* modem change int */
#define INTTHRE 0x02 /* THRE int */
#define INTRD 0x04 /* receive data int */
#define INTBRK 0x06 /* break/error int */
/*
** line status register values
*/
#define RDRDY 0x01 /* receive data ready */
#define ORUNERR 0x02 /* over-run error */
#define PARERR 0x04 /* parity error */
#define FRMERR 0x08 /* framing error */
#define BRKDET 0x10 /* break detect */
#define THREMP 0x20 /* transmit hold reg empty */
#define TSREMP 0x40 /* transmit shift reg empty */
#define TIMEOUT 0x80 /* timeout */
/*
** modem status register values
** Bits 0 - 3 define which signal(s) have changed
** with a value of 1 indicating a change has occurred
** Bits 4 - 7 indicate the current state of each of the 4 signals
*/
#define CTSCHG 0x01 /* delta CTS */
#define DSRCHG 0x02 /* delta DSR */
#define RICHG 0x04 /* delta RI */
#define DCDCHG 0x08 /* delta DCD */
#define CTS 0x10 /* Clear To Send */
#define DSR 0x20 /* Data Set Ready */
#define RI 0x40 /* Ring Indicator */
#define DCD 0x80 /* Data Carrier Detect */
/*
** macros for litecomm
*/
#define lc_setdtr(x) (lc_setmdm(x, DTR))
#define lc_setrts(x) (lc_setmdm(x, RTS))
#define lc_gotcts(x) (lc_mstat(x) & CTS)
#define lc_gotdsr(x) (lc_mstat(x) & DSR)
#define lc_gotri(x) (lc_mstat(x) & RI)
#define lc_gotdcd(x) (lc_mstat(x) & DCD)
#define lc_gotctschg(x) (lc_mstat(x) & CTSCHG)
#define lc_gotdsrchg(x) (lc_mstat(x) & DSRCHG)
#define lc_gotrichg(x) (lc_mstat(x) & RICHG)
#define lc_gotdcdchg(x) (lc_mstat(x) & DCDCHG)
#define lc_vport(x) (ports[(x-1)&0x0f])
/*
** defines to resolve differences between MSC and TURBOC
** semantics
*/
#ifdef M_I86
#define IVPTR(x) void (interrupt far *x)()
#define getvect(x) _dos_getvect(x)
#define setvect(x,y) _dos_setvect(x,y)
#define enable _enable
#define disable _disable
#define inportb(x) inp(x)
#define outportb(x,y) outp(x,y)
#define MK_FP(seg,ofs) ((void far *) \
(((unsigned long)(seg) << 16) | (unsigned)(ofs)))
#endif
#ifdef __TURBOC__
#define IVPTR(x) void interrupt (*x)()
#endif
#ifdef M_I86
#pragma pack(1)
#endif
typedef struct
{
IVPTR(orgvect); /* original vector */
unsigned orgirq; /* original irq settings */
unsigned baseport; /* baseline port */
unsigned pvector; /* int vector for port */
unsigned pirq; /* port int req mask */
volatile unsigned char mdmstat; /* current modem status */
unsigned char mdmctlr; /* current modem control values */
volatile unsigned char lasterr; /* last error return */
volatile unsigned char brkrecd; /* break was detected */
volatile unsigned char txready; /* TRUE if tranmitter available */
unsigned intmask; /* current active ints */
char far *inbuff; /* input ring buffer */
char far *inbuffend; /* internal calcs */
int inbuflen; /* size of buffer */
volatile int inbufcnt; /* chars in buffer now */
int inbufmrk; /* trigger point for xoff */
int inbufres; /* resume point for xoff */
volatile char far *inhead; /* pointer to insert */
volatile char far *intail; /* pointer to remove */
char far *stbuff; /* status ring buffer */
char far *stbuffend; /* internal calcs */
volatile char far *sthead; /* pointer to insert */
volatile char far *sttail; /* pointer to remove */
unsigned char swflow; /* TRUE if XON/XOFF active */
unsigned char swstop; /* STOP flow control char */
unsigned char swstart; /* START flow control char */
volatile unsigned char inxrecd; /* TRUE if XOFF rec'd */
volatile unsigned char outxsent; /* TRUE if XOFF sent */
unsigned char hwfrec; /* hardware flow signals */
unsigned char hwfrecmask; /* mask to use when hardware flow is ON */
unsigned char hwfxmit; /* hardware flow signals */
unsigned char hwfxmitmask; /* mask to use when hardware flow is OFF */
volatile unsigned char hwfoff; /* save state of hw flow control */
char far *outbuff; /* output ring buffer */
char far *outbuffend; /* internal calcs */
int outbuflen; /* size of buffer */
volatile int outbufcnt; /* chars in buffer now */
volatile char far *outhead; /* pointer to insert */
volatile char far *outtail; /* pointer to remove */
int rch; /* port's input char buffer */
char far *oldstk; /* save area for old stack */
char far *newstk; /* pointer to handler int stack */
char far *stkbase; /* pointer to base of int stack */
} COMM;
#ifdef M_I86
#pragma pack()
#endif
extern COMM far *ports[16];
extern unsigned _lc_error; /* error variable in lcsetup */
#undef USEHUGE
#ifdef M_I86
#ifdef M_I86CM
#define USEHUGE
#endif
#ifdef M_I86LM
#define USEHUGE
#endif
#endif
#ifdef __TURBOC__
#ifdef __COMPACT__
#define USEHUGE
#endif
#ifdef __LARGE__
#define USEHUGE
#endif
#endif
/*
** function prototypes
*/
int _portchg(unsigned, unsigned, char, unsigned);
void _lc_closeall(void);
int comm_opn(unsigned,long,unsigned,unsigned,unsigned,unsigned,unsigned,unsigned);
int comm_setup(unsigned, long, unsigned, unsigned, unsigned);
int comm_close(unsigned, unsigned);
int far comm_put(COMM far *, unsigned char);
int comm_get(COMM far *ccb);
void far commtx(COMM far *);
void far sendbyte(COMM far *, unsigned char);
int lc_get(unsigned);
int lc_getstat(unsigned, char *, char *);
int lc_put(unsigned, unsigned char);
int lc_peek(unsigned);
unsigned char lc_estat(unsigned);
int lc_getw(unsigned);
int lc_icnt(unsigned);
int lc_ocnt(unsigned);
int lc_setmdm(unsigned,unsigned);
int lc_clrmdm(unsigned,unsigned);
int lc_togmdm(unsigned,unsigned);
unsigned char lc_mstat(unsigned);
int lc_gets(unsigned,unsigned char *, int);
int lc_puts(unsigned,unsigned char *, int);
int lc_getw(unsigned);
int lc_tflush(unsigned);
int lc_rflush(unsigned);
void lc_flshtrue(unsigned, unsigned char);
int lc_nflush(unsigned, int);
int lc_xoff(unsigned,int);
int lc_gotxoff(unsigned);
int lc_putxoff(unsigned);
int lc_setxoff(unsigned, unsigned char);
int lc_setxon(unsigned, unsigned char);
int lc_sethwflow(unsigned, unsigned char);
int lc_clearhwflow(unsigned);
int lc_puthwstop(unsigned);
int lc_gothwstop(unsigned);
int lc_sbrk(unsigned);
int lc_gotbrk(unsigned);
/*
** miscellaneous functions
*/
int wait(unsigned, int, unsigned char);
void purge(unsigned);
#endif
#include "litecomm.err"